package com.itstyle.quartz.kettleUtil;

import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;

public class MavenUtil {
    //批量安装jar所在目录
//  public static String filePath = "D:/develop/apache-tomcat-8.0.9/apache-tomcat-8.0.9/webapps/activiti-rest/WEB-INF/lib";
//    public static String filePath = "D:/develop/data-integration/lib";
    public static String filePath = "D:\\develop\\dameng\\drivers\\jdbc\\jdbc";

    public static void main(String[] args) {
        LinkedList<File> linkedList = new LinkedList<>();
        File f = new File(filePath);
        File[] file = f.listFiles();
        for (int i = 0; i < file.length; i++) {
            linkedList.add(file[i]);
        }
        printFile(linkedList);
//        printFiles(linkedList);
    }

    /**
     * 功能：批量安装maven的本地的jar
     * @param args
     */
    public static void printFile(LinkedList<File> linkedList) {
        String sb = "mvn install:install-file -Dfile="+filePath+"/AA.jar -DgroupId=com.activiti -DartifactId=com.activiti.AA -Dversion=1.0.0 -Dpackaging=jar";
        for (Iterator<File> iterator = linkedList.iterator(); iterator.hasNext();) {
            File file =  iterator.next();
            if(file.isFile()){
                String fileName = file.getName();
                System.out.println(sb.replace("AA",fileName.substring(0,fileName.lastIndexOf("."))));
                linkedList.remove(file);
                printFile(linkedList);
            }else{
                break;
            }
        }
    }


    /**
     * 功能：批量引入maven的pom
     * @param args
     */
    public static void printFiles(LinkedList<File> linkedList) {
        String sb = "<dependency><groupId>com.activiti</groupId><artifactId>com.activiti.BBB</artifactId><version>1.0.0</version><type>jar</type></dependency>";
        for (Iterator<File> iterator = linkedList.iterator(); iterator.hasNext();) {
            File file =  iterator.next();
            if(file.isFile()){
                String fileName = file.getName();
                System.out.println(sb.replace("BBB",fileName.substring(0,fileName.lastIndexOf("."))));
                linkedList.remove(file);
                printFiles(linkedList);
            }else{
                break;
            }
        }
    }
}
